<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="操作时间">
              <a-range-picker :allowClear="true" ref="createdAtRangePicker" @change="createdAtRangePickerOnChange"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="账号/姓名查询">
              <a-input v-model="queryParam.account" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <s-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      showPagination="auto"
    >
    </s-table>
  </a-card>
</template>

<script>
  import { Ellipsis, STable } from '@/components'
  import { getOperationList } from '@/api/manage'

  export default {
    name: 'OperationLog',
    components: {
      STable,
      Ellipsis
    },
    data () {
      return {
        mdl: {},
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: 'id'
          },
          {
            title: '操作账号',
            dataIndex: 'causer.account'
          },
          {
            title: '操作内容',
            dataIndex: 'description'
          },
          {
            title: '操作IP',
            dataIndex: 'properties.ip'
          },
          {
            title: '操作时间',
            dataIndex: 'created_at'
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return getOperationList(Object.assign(parameter, this.queryParam)).then(res => {
            return res
          })
        }
      }
    },
    created () {

    },
    methods: {
      createdAtRangePickerOnChange (date, dateString) {
        this.queryParam.created_at_begin = dateString[0]
        this.queryParam.created_at_end = dateString[1]
      }
    }
  }
</script>
